/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import com.rall.esb.service.InfluenceDiagramService;
import com.rall.esb.service.impl.ElviraInfluenceDiagramServiceImpl;
import com.rall.esb.vo.EvidenceVO;
import java.util.Vector;

/**
 *
 * @author Alex
 */
public class TheElviraConnection {
    public static double testInfluenceDiagram(boolean bolaMagica, boolean dirPac, boolean posPac, boolean tipFan, boolean posFan) {
    InfluenceDiagramService service = null;


   service = new ElviraInfluenceDiagramServiceImpl();

   final String NODO_1 = "N1";
   final String NODO_2 = "N2";
   final String NODO_3 = "N3";
   final String NODO_4 = "N4";
   final String NODO_5 = "N5";
   final String OBJETO_1 = "O1";
   final String OBJETO_2 = "O2";
   final String DECISION = "DEC";
   final String UTILIDAD = "UTIL";


 // Se crean los nodos
   service.addNode(OBJETO_1);
   service.addNode(OBJETO_2);
   service.addNode(NODO_1);
   service.addNode(NODO_2);
   service.addNode(NODO_3);
   service.addNode(NODO_4);
   service.addNode(NODO_5);
   service.addDecisionNode(DECISION, new String[]{"Izquierda", "Derecha", "Arriba", "Abajo"});
   service.addUtilityNode(UTILIDAD);

// Se crean las relaciones
   service.addLink(DECISION, OBJETO_2);
   service.addLink(UTILIDAD, DECISION);
   service.addLink(OBJETO_1, NODO_1);
   service.addLink(OBJETO_1, NODO_2);
   service.addLink(OBJETO_1, NODO_3);
   service.addLink(OBJETO_2, NODO_4);
   service.addLink(OBJETO_2, NODO_5);
   service.addLink(OBJETO_2, OBJETO_1);

// Se asignan las probabilidades, decisiones y utilidades
   service.setNodeProbabilities(OBJETO_1, new double[]{});
   service.setNodeProbabilities(OBJETO_2, new double[]{});
   service.setNodeProbabilities(NODO_1, new double[]{0.05,0.95});
   service.setNodeProbabilities(NODO_2, new double[]{0.25,0.25,0.25,0.25});
   service.setNodeProbabilities(NODO_3, new double[]{0.25,0.25,0.25,0.25});
   service.setNodeProbabilities(NODO_4, new double[]{0.25,0.25,0.25,0.25});
   service.setNodeProbabilities(NODO_5, new double[]{0.25,0.25,0.25,0.25});
   service.setNodeUtilities(UTILIDAD, new double[]{0.9,0.8,0.9,0.7});
   service.setNodeDecisions(DECISION, new double[]{});

// Se guarda el archivo
   service.saveNetwork("c:\\", "RedPacMan");

 // Se generan las evidencias


   final Vector<EvidenceVO> evidencias = new Vector<EvidenceVO>();
   evidencias.add(new EvidenceVO(NODO_1, bolaMagica));
   evidencias.add(new EvidenceVO(NODO_2, dirPac));
   evidencias.add(new EvidenceVO(NODO_3, posPac));
   evidencias.add(new EvidenceVO(NODO_4, tipFan));
   evidencias.add(new EvidenceVO(NODO_5, posFan));

 // Se propaga la evidencia
   service.propagate(evidencias);

 // Se obtiene el resultado de la decisión
   final String resultado = service.getDecision(DECISION);

   return Double.parseDouble(resultado);


    }
}
